package com.ts.tscloud.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.ts.tscloud.mapper.UserMapper;
import com.ts.tscloud.pojo.po.User;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class UserController {
    @Autowired
    private UserMapper userMapper;

    @Autowired
    private RedisTemplate<String,Object> redisTemplate;

    @RequestMapping("/a")
    @ResponseBody
    public  String  selectUser() throws JsonProcessingException {
        ObjectMapper objectMapper = new ObjectMapper();

        List<User> users = userMapper.selectUser();
        for (User user:users){
            System.out.println(user);
            System.out.println("从缓存的数据");
            redisTemplate.opsForValue().set("user",user);
            System.out.println(redisTemplate.opsForValue().get("user"));
        }
        String s = objectMapper.writeValueAsString(users);


        System.out.println(s);
        return "ok";


    }

}
